import 'dart:async';

import 'package:chop/widgets/TextSizeWidget.dart';
import 'package:chop/widgets/appBar.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:loading_animations/loading_animations.dart';

//正在进行订单
class OrdedrUnfinished extends StatefulWidget {
  @override
  _OrdedrUnfinishedState createState() => _OrdedrUnfinishedState();
}

class _OrdedrUnfinishedState extends State<OrdedrUnfinished> {
  // 是否在网络请求中
  bool isNetworkNotBad = false;

//  GoogleMapPolyline googleMapPolyline =
//  GoogleMapPolyline(apiKey: Configs.API_KEY);

  // 地图控制器
  Completer<GoogleMapController> _controller = Completer();

  Widget getBody() {
    if (!isNetworkNotBad) {
      print("加载完成");
      return ListView.builder(
        itemBuilder: (context, index) {
          return _buildBody();
        },
        itemCount: 5,
      );
    } else {
      print("正在加载");
      return Center(child: LoadingJumpingLine.square());
    }
  }

  Widget _buildBody() {
    return Container(
      width: MediaQuery.of(context).size.width,
      height: MediaQuery.of(context).size.height,
      child: Stack(
        children: <Widget>[
          Positioned(
            top: 10,
            width: MediaQuery.of(context).size.width,
            child: Container(
                width: double.infinity, height: 500, color: Colors.black),
          ),
          Positioned(
            top: 0,
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
            child: GoogleMap(
              myLocationEnabled: true,
              myLocationButtonEnabled: true,
              initialCameraPosition: CameraPosition(
                target: LatLng(38.0138856200, 114.5085819100),
                zoom: 14.4746,
              ),
              onMapCreated: (GoogleMapController controller) {
                _controller.complete(controller);
              },
            ),
          ),
          Container(
            child: ListView(
              children: <Widget>[
                Container(
                  height: 500,
                ),
                Container(
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.all(Radius.circular(17)),
                        color: Colors.white),
//                  height: 50,
                    width: double.infinity,
                    margin: EdgeInsets.fromLTRB(15, 5, 15, 5),
                    child: Column(
                      children: <Widget>[
                        Container(
                          padding: EdgeInsets.fromLTRB(15, 5, 15, 0),
                          decoration: BoxDecoration(
                              border: Border(
                                  bottom: BorderSide(
                                      color: Colors.black, width: 1)),
                              color: Colors.white),
                          child: Row(
                            children: <Widget>[
                              Expanded(
                                child: Column(
                                  children: <Widget>[
                                    Row(
                                      children: <Widget>[
                                        Container(
//                        width: double.infinity,
                                          padding: EdgeInsets.only(
                                              top: 5, bottom: 5),
                                          child: FixedSizeText(
                                            "大众牌自行车",
                                            textAlign: TextAlign.start,
                                            style: TextStyle(
                                                fontSize: 16,
                                                fontWeight: FontWeight.bold),
                                          ),
                                        )
                                      ],
                                    ),
                                    Container(
                                      padding:
                                          EdgeInsets.only(top: 5, bottom: 5),
                                      child: Row(
                                        children: <Widget>[
                                          Container(
                                            child: FixedSizeText("xxx姓名"),
                                          ),
                                          Container(
                                            width: 15,
                                          ),
                                          Icon(
                                            Icons.star,
                                            size: 15,
                                          ),
                                          FixedSizeText("5.0")
                                        ],
                                      ),
                                    ),
                                  ],
                                ),
                                flex: 8,
                              ),
                              Expanded(
                                flex: 2,
                                child: CircleAvatar(child: Icon(Icons.people)),
                              )
                            ],
                          ),
                        ),
                        Row(
                          children: <Widget>[
                            _getButton("按钮1"),
                            _getButton("按钮1"),
                            _getButton("按钮1"),
                            _getButton("按钮1"),
                            _getButton("按钮1"),
                          ],
                        )
                      ],
                    ))
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _getButton(
    String title, {
    Icon icon,
    VoidCallback click,
  }) {
    return Expanded(
      flex: 2,
      child: GestureDetector(
        child: Center(heightFactor:2,child: FixedSizeText(title)),
        onTap: click,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: BaseViewBar(
        childView: BaseTitleBar("订单详情"),
        preferredSize: Size.fromHeight(50.0),
      ),
      body: getBody(),
    );
  }
}
